package com.qasystem.qa.system.controller;

import com.qasystem.qa.core.base.BaseController;
import com.qasystem.qa.core.base.BaseEnum;
import com.qasystem.qa.core.base.Result;
import com.qasystem.qa.core.constants.BaseEnums;
import com.qasystem.qa.core.scurity.ScurityUser;
import com.qasystem.qa.core.service.LoginService;
import com.qasystem.qa.core.service.RedisService;
import com.qasystem.qa.core.utils.Results;
import com.qasystem.qa.system.entity.User;
import com.qasystem.qa.system.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@RequestMapping("/public")
@Controller
public class UserController extends BaseController {
    protected static List<User>  userList = new ArrayList<>();
    @Autowired
    private UserService userService;
    @Autowired
    private RedisService redisService;

    static {
        User user1 = new User();
        user1.setUserid("1");
        user1.setMajorid(1);
        user1.setUsername("娜美");
        user1.setAccount("3w3549546");
        user1.setLevel(2);
        user1.setLocation("hgfdgd");
        user1.setPassword("xdhge");
        User user2 = new User();
        user2.setUserid("2");
        user2.setMajorid(1);
        user2.setUsername("娜美");
        user2.setAccount("3w3549546");
        user2.setLevel(2);
        user2.setLocation("hgfdgd");
        user2.setPassword("xdhge");
        userList.add(user1);
        userList.add(user2);
    }
    @RequestMapping("/queryAll")
    public Result queryAll() {
        return Results.successWithData(userList, BaseEnums.SUCCESS.code(), BaseEnums.SUCCESS.desc());
    }

    @RequestMapping("/queryOne/{userId}")
    public Result queryOne(@PathVariable String userId) {
        User user = null;
        for (User u : userList) {
            if (u.getUserid() == userId) {
                user = u;
            }
        }
        return Results.successWithData(user);
    }
    @RequestMapping("/selectIds")
    public Result selectByIds () {
        String ids = "1,2";
        List<User> list = userService.select(ids);
        return Results.successWithData(list);
    }

    @GetMapping("/userInfo")
    public String getUserInfo () {
//        ScurityUser user = (ScurityUser) redisService.get(token);
//        if (user != null) {
//            System.out.println("username: " + user.getUserName());
//            //User u = userService.get(user.getUserId());
//            //System.out.println("user " + u.getUsername());
//            return Results.successWithData(user, BaseEnums.SUCCESS.code(), BaseEnums.SUCCESS.desc());
//        }
//        return Results.failure(BaseEnums.FAILURE.code(), BaseEnums.FAILURE.desc());
        return "userInfo/index";

    }




}
